
package ac.il.technion.cs236635.project.core.policy;

import java.util.List;

import org.apache.log4j.Logger;

import ac.il.technion.cs236635.project.core.ServerJob;

public class LimittedBufferPolicy implements AcceptancePolicy {

	private Logger log = Logger.getLogger( LimittedBufferPolicy.class);
	
	private Integer queueSize = 0;

	public LimittedBufferPolicy( ) {
		
	}
	
	public LimittedBufferPolicy( int queueSize) {
		this.queueSize = queueSize;
	}
	
	// Just drop the job without any notification
	@Override
	public synchronized boolean accept(ServerJob job, List<ServerJob> queue) {
		log.debug( "POLICY: Job id: " + job.getJobId( ) + "Queue size: " + queue.size( ) + ", " + job.getJobType( ) + " [" + queue.hashCode( ) + "]");
		if ( queue.size( ) >= queueSize)
			return false;
		queue.add( queue.size( ), job);
		return true;
	}

}
